/*
 * Copyright (c) 2015 elion. All Rights Reserved.
 */
package com.guoyu.project.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.dao.BannerDao;
import com.guoyu.project.model.Banner;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;

/**
 * banner信息,业务类BannerService
 *
 * @author: xblibo Sat Jun 27 14:00:13 CST 2015
 * @version 1.0
 */
@Service
public class BannerService {

    @Resource
    private BannerDao bannerDao;

    /**
     * 保存banner信息数据
     *
     * @param banner
     */
    public void saveBanner(Banner banner) {
        bannerDao.save(banner);
    }

    /**
     * 更新banner信息实体
     *
     * @param banner
     */
    public void updateBanner(Banner banner) {
        bannerDao.update(banner);
    }

    /**
     * 删除banner信息数据
     *
     * @param bannerId
     */
    public void deleteById(int bannerId) {
        bannerDao.deleteById(bannerId);
    }

    /**
     * 根据id获取banner信息数据
     *
     * @param bannerId
     * @return
     */
    public Banner queryById(int bannerId) {
        return bannerDao.queryById(bannerId);
    }

    /**
     * 根据条件分页查询banner信息数据
     *
     * @param offset
     * @param limit
     * @param params
     * @return
     */
    public Pagination<Banner> queryBanners(int offset, int limit, Map<String, Object> params) {
        // 根据条件获取总记录数
        int total = bannerDao.queryBannerCount(params);

        // 构建分页对象，参数
        if (null == params) {
            params = Maps.newHashMap();
        }
        params.put(Pagination.OFFSET, offset);
        params.put(Pagination.LIMIT, limit);

        // 分页查询数据
        List<Banner> bannerList = bannerDao.queryBanners(params);
        return new Pagination(offset, limit, total, bannerList);
    }

    public List<Banner> queryBanners(Map<String, Object> params) {
        return bannerDao.queryBanners(params);
    }
}